package com.fin.zw.intelligentbot.controller;

import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.entity.AiAccount;
import com.fin.zw.intelligentbot.model.request.AiAccountRequest;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.AiAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/ai/account")
@Api(value = "ai语音账号管理",description = "ai语音账号管理")
public class AiAccountController {

    @Autowired
    private AiAccountService aiAccountService;

    @GetMapping("/fetchPage")
    @ApiOperation(value = "查询所有的ai语音账号信息",notes = "查询所有的ai语音账号信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<AiAccount>> queryAiAccountAll(Pageable pageable,
                                                           @RequestParam(value = "name",required = false) String name,
                                                           @ApiIgnore @CurrentUser SessionModel sessionModel){
        Page<AiAccount> page = aiAccountService.queryAiAccount(pageable,sessionModel,name);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/fetch")
    @ApiOperation(value = "查询所有的ai语音账号信息",notes = "查询所有的ai语音账号信息")
    public ResponseEntity<List<AiAccount>> getAiAccountList(@ApiIgnore @CurrentUser SessionModel sessionModel){
        List<AiAccount> list = aiAccountService.getAiAccountList(sessionModel);
        return ResponseEntity.ok().body(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "ai语音账号信息添加",notes = "ai语音账号信息添加")
    public ResponseEntity<String> createAiAccount(@RequestBody AiAccountRequest request,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        aiAccountService.createAiAccount(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @RequestMapping(value = "/update",method = {RequestMethod.PUT,RequestMethod.PATCH})
    @ApiOperation(value = "ai语音账号信息更新",notes = "ai语音账号信息更新")
    public ResponseEntity<String> updateAiAccount(@RequestBody AiAccountRequest request,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        aiAccountService.updateAiAccount(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }
}
